package com.songcha.sakura.ui.view.test

import android.content.Context
import android.graphics.*
import android.util.AttributeSet
import android.view.ViewGroup

class TestView
@JvmOverloads
constructor(
    context: Context,
    attrs: AttributeSet? = null,
    defStyle: Int = 0,
    defRes: Int = 0
) : ViewGroup(context, attrs, defStyle, defRes) {



    init {
        setWillNotDraw(false)
    }

    override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) {
        super.onMeasure(widthMeasureSpec, heightMeasureSpec)

        for (i in 0 until childCount) {
            val child = getChildAt(i)
            measureChildWithMargins(child, widthMeasureSpec, 0, heightMeasureSpec, 0)
        }

        //measureChildWithMargins(child,widthMeasureSpec,0,heightMeasureSpec,0)
        //measureChildren(widthMeasureSpec,heightMeasureSpec)
    }

    override fun onLayout(changed: Boolean, l: Int, t: Int, r: Int, b: Int) {
        if(childCount>0){
            val child=getChildAt(0)
            child.layout(0,0,child.measuredWidth,child.measuredHeight)

        }


    }






    override fun onDraw(canvas: Canvas?) {
        super.onDraw(canvas)
        if(canvas==null) return

    }


}